package myalg.graphs.alg;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author Pavel Belevich
 *         Date: Jul 23, 2012
 *         Time: 3:15:16 PM
 */
public abstract class BasicAlgorithm implements Algorithm {

    private Collection<AlgorithmListener> listeners = new ArrayList<AlgorithmListener>();

    public void addAlgorithmListener(AlgorithmListener listener) {
        this.listeners.add(listener);
    }

    public void removeAlgorithmListener(AlgorithmListener listener) {
        this.listeners.remove(listener);
    }

    protected void step() {
        for (AlgorithmListener listener : this.listeners) {
            listener.step();
        }
    }

    protected void sleep(long millis) {
        try {
            Thread.sleep(millis);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
